﻿using AnQinManagermentBackendAPI.Model.DTO.SaleManagement;
using AnQinManagermentBackendAPI.Model.View.SaleManagement;
using AnQinManagermentBackendAPI.Service;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace AnQinManagermentBackendAPI.Controller
{
    /// <summary>
    /// 销售管理表
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class SaleManagementController : ControllerBase
    {
        /**
         * 销售管理业务接口
         */
        private readonly SaleManagementService _saleManagementService;

        /**
         * 构造函数注入
         */
        public SaleManagementController(SaleManagementService saleManagementService)
        {
            _saleManagementService = saleManagementService;
        }

        /// <summary>
        /// 获取销售管理列表
        /// </summary>
        /// <param name="saleManagementSearchDTO"></param>
        [HttpGet]
        [ProducesResponseType(typeof(SaleManagementView), 200)]
        public async Task<IActionResult> GetSaleManagementList([FromQuery] SaleManagementSearchDTO saleManagementSearchDTO)
        {
            var response = await _saleManagementService.GetSaleManagementList(saleManagementSearchDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 新增销售管理
        /// </summary>
        /// <param name="saleManagementAddDTO"></param>
        [HttpPost]
        public async Task<IActionResult> AddSaleManagement([FromBody] SaleManagementAddDTO saleManagementAddDTO)
        {
            var response = await _saleManagementService.AddSaleManagement(saleManagementAddDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 更新销售管理
        /// </summary>
        /// <param name="saleManagementUpdateDTO"></param>
        [HttpPut]
        public async Task<IActionResult> PutSaleManagement([FromBody] SaleManagementUpdateDTO saleManagementUpdateDTO)
        {
            var response = await _saleManagementService.PutSaleManagement(saleManagementUpdateDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 删除销售管理
        /// </summary>
        [HttpDelete]
        public async Task<IActionResult> DeleteSaleManagement([FromQuery] string Id)
        {
            var response = await _saleManagementService.DeleteSaleManagement(Id);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 确认销售
        /// </summary>
        [HttpPost("Confirm")]
        public async Task<IActionResult> ConfirmSaleManagement([FromBody] string Id)
        {
            var response = await _saleManagementService.ConfirmSaleManagement(Id);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 取消销售
        /// </summary>
        [HttpPost("Cancel")]
        public async Task<IActionResult> CancelSaleManagement([FromBody] string Id)
        {
            var response = await _saleManagementService.CancelSaleManagement(Id);
            return StatusCode(response.Status, response);
        }
    }
}
